<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增用户基本信息')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: select2-css" />
</head>
<body>
    <div class="main-content">
        <form enctype="multipart/form-data" class="form-horizontal m" id="form-user-add">
            <input name="deptId" type="hidden" id="deptId"/>
            <div class="row">
                <div class="col-sm-6 b-r">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">工号：</label>
                        <div class="col-sm-8">
                            <input id="userNo" name="userNo" placeholder="请输入工号" class="form-control" type="text" maxlength="20">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">姓名：</label>
                        <div class="col-sm-8">
                            <input name="name" placeholder="请输入姓名" class="form-control" type="text">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">性别：</label>
                        <div class="col-sm-8">
                            <select name="sex" class="form-control m-b" th:with="type=${@dict.getType('sys_user_sex')}">
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">所属部门：</label>
                        <div class="col-sm-8">
                            <div class="input-group">
                                <input name="deptName" onclick="selectDeptTree()" id="deptName" type="text" placeholder="请选择归属部门" class="form-control">
                                <span class="input-group-addon"><i class="fa fa-search"></i></span>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">管理科室：</label>
                        <div class="col-sm-8">
                            <select name="userDept" class="form-control m-b" th:with="type=${@dict.getType('basic_user_dept')}">
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-3 control-label">照片：</label>
                        <div class="col-sm-8">
                            <img id="image" width="150" height="150">
                            <input accept="image/*" id="file" name="file" th:onchange="gen_base64()" type="file">
                            <font color="red" class="pull-left mt10">
                                提示：仅允许导入图片文件！
                            </font>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">来院日期：</label>
                        <div class="col-sm-8">
                            <div class="input-group date">
                                <input name="hospitalTime" class="form-control" placeholder="yyyy-MM-dd" type="text">
                                <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">离院日期：</label>
                        <div class="col-sm-8">
                            <div class="input-group date">
                                <input name="levelTime" class="form-control" placeholder="yyyy-MM-dd" type="text">
                                <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">出生日期：</label>
                        <div class="col-sm-8">
                            <div class="input-group date">
                                <input name="birthday" class="form-control" placeholder="yyyy-MM-dd" type="text">
                                <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">民族：</label>
                        <div class="col-sm-8">
                            <select name="nationType" class="form-control m-b" th:with="type=${@dict.getType('basic_user_nation')}">
                                <option value="">请选择</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">政治面貌：</label>
                        <div class="col-sm-8">
                            <select name="politicalType" class="form-control m-b" th:with="type=${@dict.getType('basic_user_political')}">
                                <option value="">请选择</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">组织时间：</label>
                        <div class="col-sm-8">
                            <div class="input-group date">
                                <input name="politicalTime" class="form-control" placeholder="yyyy-MM-dd" type="text">
                                <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">手机号码：</label>
                        <div class="col-sm-8">
                            <input name="phonenumber" id="phonenumber" placeholder="请输入手机号码" class="form-control" type="text" maxlength="11">
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">身份证号：</label>
                        <div class="col-sm-8">
                            <input name="idCard" placeholder="请输入身份证号" class="form-control" type="text" required maxlength="18">
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">人员类型：</label>
                        <div class="col-sm-8">
                            <select name="userType" class="form-control m-b" th:with="type=${@dict.getType('basic_user_type')}">
                                <option value="">请选择</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">婚姻状况：</label>
                        <div class="col-sm-8">
                            <select name="marryType" class="form-control m-b" th:with="type=${@dict.getType('basic_user_marry')}">
                                <option value="">请选择</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">健康状况：</label>
                        <div class="col-sm-8">
                            <select name="healthStatus" class="form-control m-b" th:with="type=${@dict.getType('basic_user_health')}">
                                <option value="">请选择</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">籍贯：</label>
                        <div class="col-sm-8">
                            <input name="regionName" placeholder="请输入籍贯" class="form-control" type="text">
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">技术类别：</label>
                        <div class="col-sm-8">
                            <select name="technicalType" class="form-control m-b" th:with="type=${@dict.getType('basic_user_technical')}">
                                <option value="">请选择</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">职位类别：</label>
                        <div class="col-sm-8">
                            <select name="userPosition" class="form-control m-b" th:with="type=${@dict.getType('basic_user_position')}">
                                <option value="">请选择</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">考勤分类：</label>
                        <div class="col-sm-8">
                            <select name="attendType" class="form-control m-b" th:with="type=${@dict.getType('attend_type')}">
                                <option value="">请选择</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">岗位属性：</label>
                        <div class="col-sm-8">
                            <select name="postType" class="form-control m-b" th:with="type=${@dict.getType('post_type')}">
                                <option value="">请选择</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">社会兼职情况：</label>
                        <div class="col-sm-8">
                            <input name="holdWork" class="form-control" type="text">
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">工龄起算日期：</label>
                        <div class="col-sm-8">
                            <div class="input-group date">
                                <input name="seniorityStart" class="form-control" placeholder="yyyy-MM-dd" type="text">
                                <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-xs-2 control-label">详细地址：</label>
                <div class="col-xs-10">
                    <input name="address" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-xs-2 control-label">备注：</label>
                <div class="col-xs-10">
                    <textarea name="remark" maxlength="500" class="form-control" rows="3"></textarea>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: select2-js" />
    <script th:inline="javascript">
        var prefix = ctx + "basic/user"
        $("#form-user-add").validate({
            onkeyup: false,
            rules:{
                userNo:{
                    remote: {
                        url: prefix + "/checkUserNoUnique",
                        type: "post",
                        dataType: "json",
                        data: {
                            "userNo": function() {
                                return $.common.trim($("#userNo").val());
                            }
                        },
                        dataFilter: function(data, type) {
                            return $.validate.unique(data);
                        }
                    }
                },
                idCard:{
                    minlength: 15,
                    maxlength: 18,
                    remote: {
                        url: prefix + "/checkIdCardUnique",
                        type: "post",
                        dataType: "json",
                        data: {
                            "idCard": function () {
                                return $.common.trim($("#idCard").val());
                            }
                        },
                        dataFilter: function (data, type) {
                            return $.validate.unique(data);
                        }
                    }
                },
                phonenumber:{
                    isPhone:true
                }
            },
            messages: {
                "userNo": {
                    remote: "工号已经存在"
                },
                "idCard": {
                    remote: "身份证号已经存在"
                },
                "phonenumber": {
                    remote: "手机号码不正确"
                }
            },
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                var formData = new FormData($('#form-user-add')[0]);
                $.operate.saveFile(prefix + "/add", formData);
            }
        }

        $("input[name='birthday']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("input[name='hospitalTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("input[name='leaveTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("input[name='politicalTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("input[name='seniorityStart']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        /* 用户管理-新增-选择部门树 */
        function selectDeptTree() {
            var treeId = $("#deptId").val();
            var deptId = $.common.isEmpty(treeId) ? "100" : $("#deptId").val();
            var url = ctx + "system/dept/selectDeptTree/" + deptId;
            var options = {
                title: '选择部门',
                width: "380",
                url: url,
                callBack: doSubmit1
            };
            $.modal.openOptions(options);
        }

        function doSubmit1(index, layero){
            var tree = layero.find("iframe")[0].contentWindow.$._tree;
            var body = layer.getChildFrame('body', index);
            $("#deptId").val(body.find('#treeId').val());
            $("#deptName").val(body.find('#treeName').val());
            layer.close(index);
        }

        function gen_base64(){
            var file = document.getElementById("file").files[0];
            var size = file.size;
            if(size > 10 * 1024 * 1024){
                $.modal.alertError("超出图片最大限制：10M");
                return;
            }
            var r = new FileReader();
            r.readAsDataURL(file);
            r.onload = function (){
                document.getElementById("image").src = r.result;
            }
        }
    </script>
</body>
</html>